home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Compression / Opener / Source / monitor.m < prev    next >
Text File  |  1993-07-19  |  3KB  |  103 lines

  1. /*
  2.  * Implement the "suggestion" box, to catch user's comments,
  3.  * and also a simple tracking mechanism, to send a blip of
  4.  * mail from the first-time user.  This is akin to releasing
  5.  * helium balloons with postcards that say "If you find me,
  6.  * send this card back to . . ." -- it should be interesting
  7.  * to the community to track the free flow of software on
  8.  * the ethernet.
  9.  *
  10.  * If you have any concerns about this, please check with me.
  11.  *
  12.  * Michael Hawley
  13.  * mike@media-lab.mit.edu
  14.  */
  15.  
  16. #define _NAME "Opener"
  17.  
  18. static char *stripnl(char *s){
  19.     char *p;
  20.     for (p=s;*p;p++) if (*p == '\n' || *p == '\r') *p = '\0';
  21.     return s;
  22. }
  23.  
  24. char *
  25. execstr(s) char *s; {
  26.     FILE *f = popen(s,"r");
  27.     char *p = s;
  28.     *s = '\0';
  29.     if (f){
  30.         while (fgets(p,256,f))
  31.             stripnl(p), p += strlen(p);
  32.         pclose(f);
  33.     }
  34.     return s;
  35. }
  36.  
  37. static void
  38. monitorMail(subj,body,dest) char *subj, *body, *dest; {
  39.     char s[1024], u[256]="whoami", m[256]="hostname", t[4096];
  40.     FILE *f, *popen();
  41.     if (!dest || !*dest) dest = "monitor%tome.media.mit.edu@mit.edu";
  42.     execstr(u); execstr(m);
  43.     if (!body || !*body){
  44.         body = t;
  45.         sprintf(body, "%s@%s\nIf this mail bounces back to you,\n\
  46. could you please correct the destination path if possible,\n\
  47. and send it to monitor@tome.media.mit.edu.\n\
  48. We are trying an experiment to track software.\n",u,m);
  49.     }
  50.     sprintf(s,"/usr/ucb/Mail -s \"%s %s@%s\" %s",
  51.     subj && *subj? subj : [NXApp appName], u, m, dest);
  52.     if (f = popen(s,"w"))
  53.         fprintf(f,"%s",body), pclose(f);
  54. }
  55.  
  56. static void
  57. OpenerMonitor(subj) char *subj; { // send a note at first use.  to track net.
  58.     extern char FirstUsed[];
  59.     if (!*FirstUsed){
  60.         extern long time();
  61.         extern char *ctime();
  62.         long t = time(0);
  63.         if (t < 793414430) // 1995 
  64.         monitorMail(subj,0,0);
  65.         strcpy(FirstUsed,ctime(&t));
  66.         stripnl(FirstUsed);
  67.         [_defaults writeDefaults:_defaults];
  68.     }
  69. }
  70.  
  71. - suggestion:sender {
  72.     char subj[256], w[256] = "whoami";
  73.     char body[4096]="\
  74. Michael:\n\n\
  75. A handy bit of software!  I use it ALL the time.\n\
  76. Now, I know I should be sending you a T shirt, a card, \n\
  77. maybe a tax deductible surprise to further your\n\
  78. student career, indeed I know I could send it to you\n\
  79. at the MIT Media Lab / 20 Ames St / Cambridge, MA 02139\n\
  80. but all I have are these scrimpy electronic comments:\n\n\
  81.    <insert accolades & suggestions here>\n\n\
  82.              parsimoniously,\n\
  83.              ";
  84. #define fcall(a)  [s performRemoteMethod:a]
  85. #define call(a,b) [s performRemoteMethod:a with:b length:strlen(b)+1]
  86.     id s = [NXApp appSpeaker];
  87.     NXPortFromName("Mail", NULL); // make sure app is launched
  88.     [s setSendPort:NXPortFromName("MailSendDemo", NULL)];
  89.  
  90.     sprintf(subj,"Comments and suggestions for ``%s'' ",_NAME);
  91.     strcat(subj,[version stringValue]);
  92.     strcat(body,execstr(w)); strcat(body,"\n");
  93.     call("setTo:","comments@tome.media.mit.edu");
  94.     call("setSubject:",subj);
  95.     call("setBody:",body);
  96.     
  97.     return self;
  98. }
  99.  
  100. /*
  101.     OpenerMonitor("Opener-1.0-newuser");
  102. */
  103.